<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
	String maintenance_id=request.getParameter("id");//取得传递过来的用户参数，用于查询和删除
	System.out.println(maintenance_id);
	Connection conn=null;
	try{
		Class.forName("org.h2.Driver");//加载驱动
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
		return;
	}
	try {
		conn = DriverManager.getConnection("jdbc:h2:d:/CompanyCar/temp/mydbtest", "sa", "");
		String sql="update car_maintenance set maintenance_date=?, maintenance_mileage=?, next_maintenance_date=?, next_maintenance_mileage=?, maintenance_type=?, maintenance_cost=?, handler=?, register_person=?, register_date=?, last_modifier=?, last_modify_date=?, maintenance_item=?, maintenance_location=?, remark=? where maintenance_id='"+maintenance_id+"'";
		PreparedStatement pstmt  = conn.prepareStatement(sql);
    	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    	java.util.Date date=null;
    	String dateString=request.getParameter("保养时间");
    	date= dateFormat.parse(dateString);
    	java.sql.Date maintenance_date = new java.sql.Date(date.getTime());
    	System.out.println(maintenance_date);
    	pstmt.setDate(1,maintenance_date);
    	pstmt.setFloat(2,Float.parseFloat(request.getParameter("保养里程")));
    	dateString = request.getParameter("下次保养时间");
    	date = dateFormat.parse(dateString);
    	java.sql.Date next_maintenance_date = new java.sql.Date(date.getTime());
    	pstmt.setDate(3,next_maintenance_date);
    	pstmt.setFloat(4,Float.parseFloat(request.getParameter("下次保养里程")));
    	pstmt.setString(5,request.getParameter("保养类型"));
    	pstmt.setFloat(6,Float.parseFloat(request.getParameter("本次保养费用")));
    	pstmt.setString(7,request.getParameter("经办人"));
    	pstmt.setString(8,request.getParameter("登记人"));
    	dateString = request.getParameter("登记时间");
    	date = dateFormat.parse(dateString);
    	java.sql.Date register_date = new java.sql.Date(date.getTime());
    	System.out.println(register_date);
    	pstmt.setDate(9,register_date);
    	pstmt.setString(10,request.getParameter("最新一次修改人"));
    	dateString = request.getParameter("最新一次修改时间");
    	date = dateFormat.parse(dateString);
    	java.sql.Date last_modify_date = new java.sql.Date(date.getTime());
    	pstmt.setDate(11,last_modify_date);
    	pstmt.setString(12,request.getParameter("保养项目"));
    	pstmt.setString(13,request.getParameter("保养地点"));
    	pstmt.setString(14,request.getParameter("备注"));
		System.out.println(sql);
		//执行数据库插入，获取结果集
		int result=pstmt.executeUpdate();
		System.out.println(result);
		//关闭表达式对象
		pstmt.close();			
		//关闭数据库				
		conn.close();
	} catch (SQLException e) {
		e.printStackTrace();
	} finally{
	//防止数据库未正常关闭
	try{
		if (conn!=null && (!conn.isClosed())){
			conn.close();
		}
	}catch(SQLException e){
		e.printStackTrace();
	}
}
	response.sendRedirect("D-Details_maintenance.jsp");
%>


</body>
</html>